/**
 * Created by Administrator on 2015/9/17.
 */
//module game{
    class BuffItemRender extends eui.ItemRenderer{
        private frameItem:FrameItem;
        public static NUM:number = 0;
        public constructor(){
            super();
            this.skinName = "pet.BuffItemRenderSkin";
            this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAdded, this);
            this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemoved, this);
            this.name = "buffitemrender"+BuffItemRender.NUM;
            this.frameItem = new FrameItem();
            this.frameItem.callFun = this.update;
            this.frameItem.callObj = this;
            BuffItemRender.NUM++;
        }

        public update(delta:number){
            //var cnt:number = Math.round(PetMgr.getInstance().curPet.autoHairPer*this.data.addition/100);
            var cnt:number =this.data.addition;
            this.speed_group.text = "+"+cnt;
            if( this.data.isItem){
                var pernant:eui.Image = new eui.Image(RES.getRes("img_pernant"));
                this.group_time.text = "y";
            }else{
                var timegap = this.data.endTime - Model.SYSTIME;
                if( timegap > 0){
                    var timestr = GetTimeStr(timegap,2,true);
                    this.group_time.text = timestr;
                }else{
                    //todo how
                }
            }
        }

        private onAdded(evt:egret.TouchEvent){
            FrameMgr.getInstance().addControll(this.frameItem);
        }

        private onRemoved(evt:egret.TouchEvent){
            FrameMgr.getInstance().delController(this.name);
        }

        public dataChanged(){
            super.dataChanged();
            this.img_icon.source = GameConst.Res_Root+"resource/assets/items/"+this.data.buffId+".png";
        }

        public img_icon:eui.Image;
        public speed_group:eui.BitmapLabel;
        public group_time:eui.BitmapLabel;
        public partAdded(name:string, instance:any){
            super.partAdded(name, instance);
            if( name == "img_icon" ){
                this.img_icon = instance;
            }else if( name == "speed_group" ){
                this.speed_group = instance;
            }else if( name == "group_time" ){
                this.group_time = instance;
            }
        }
    }
//}